package dao.hibernate;

import dao.common.OrderManager;
import models.shop.Order;
import models.shop.OrderStatus;

import java.util.List;

public class OrderManagerHB implements OrderManager {
    public Order getById(int id) {
        Order order = Order.findById(id);
        return order;
    }

    public List<Order> getUnconfirmed() {
        return Order.find("select o from Order o where o.status is null or o.status = 'unconfirmed'").fetch();
    }

    public void delete(int id) {
        Order.delete("from Order where id = ?", id);
    }

    public void setStatus(int orderId, OrderStatus status) {
        Order order = Order.findById(orderId);
        order.status = status.toString();
        order.save();
    }
}
